package com.dream.springmvc;



import com.dream.springmvc.value.*;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

/**
 * @author 陈根
 */
@Getter
@Schema(description = "字段类型 ", format = "enum",
        allowableValues = {
                "input #单行文本",
                "textarea #多行文本",
                "select #单选",
                "multiSelect #多选",
                "number #数字",
                "amount #金额",
                "datePicker #日期",
                "upload #文件",
                "table #表格",
                "selectWithData #单选关联数据项",
                "multiSelectWithData  #多选关联数据项",
        },
        requiredMode = Schema.RequiredMode.REQUIRED,
        example = "input", type = "string")
public enum FieldTypeEnum {
    SINGLE_LINE_TEXT(
            "input",
            "单行文本",
//            SingleLineField.class,
            SingleLineTextValue.class),
    MULTILINE_TEXT(
            "textarea",
            "多行文本",
//            MultilineLineField.class,
            SingleLineTextValue.class),
    // 单选
    SINGLE_SELECT(
            "select",
            "单选",
//            SingleSelectField.class,
            SingleSelectValue.class),
    // 多选
    MULTI_SELECT(
            "multiSelect",
            "多选",
//            MultiSelectField.class,
            MultiSelectValue.class
    ),
    // 数字
    NUMBER(
            "number",
            "数字",
//            NumberField.class,
            NumberValue.class
    ),
    // 金额
    AMOUNT(
            "amount",
            "金额",
//            AmountField.class,
            AmountValue.class
    ),
    // 日期
    DATE(
            "datePicker",
            "日期",
//            DateField.class,
            DatetimeValue.class
    ),
    // 文件
    FILE(
            "upload",
            "文件",
//            FileField.class,
            FileValue.class
    ),
    // 表格
    SHEET(
            "table",
            "表格",
//            SheetField.class,
            SheetValue.class),
    // 单选关联数据项
    SELECT_WITH_DATA(
            "selectWithData",
            "单选关联数据项",
//            SingleSelectWithDataField.class,
            SelectWithDataValue.class),
    // 多选关联数据项
    MULTI_SELECT_WITH_DATA(
            "multiSelectWithData",
            "多选关联数据项",
//            MultiSelectWithDataField.class,
            SelectWithDataValue.class);

    @JsonValue
    private final String value;

    private final String name;


    private final Class<? extends Value<?>> fieldValue;

    FieldTypeEnum(String value,
                  String name,
//                  Class<? extends AbstractField> fieldClass,
                  Class<? extends Value<?>> fieldValue

    ) {
        this.value = value;
        this.name = name;
//        this.fieldClass = fieldClass;
        this.fieldValue = fieldValue;
    }

    @JsonCreator
    public static FieldTypeEnum fromJson(String value) {
        for (FieldTypeEnum b : FieldTypeEnum.values()) {
            if (String.valueOf(b.value).equals(value)) {
                return b;
            }
        }
        return null;
//        throw new DataException(DataStatusCodeEnum.FieldTypeNotExist);
    }
}

